<template>
    <div id="print-box">
        <div class="fill-wrap  not-print">
            <a href="javascript:void(0)" class="btn cancel-btn" @click="printCancel">返回</a>
            <a href="javascript:void(0)" class="btn print-btn" @click="printContent">打印</a>
        </div>
        <div class="order-lis" id="orderlist-print">
            <h3 class="title">泰科院内转运登记表</h3>
            <div class="print-info">
                <span class="time"> 打印时间：{{ptime}} </span>
                <div class="ks"><div>打印科室：{{pks}}</div></div>
            </div>
            <div class="table-wrap">
                <table style="font-size: 9pt;border:1px solid #000">
                    <thead>
                    <tr>
                        <td style="width:2.1cm">姓名/床号</td>
                        <td style="width:2.5cm">检查项目</td>
                        <td style="width:2.6cm">预约时间</td>
                        <td style="width:2.2cm">携带工具</td>
                        <td style="width:2.5cm">备注</td>
                        <td style="width:1.8cm">下单人</td>
                        <td style="width:2.2cm">接单人</td>
                        <td style="width:2cm">护士签名</td>
                    </tr>
                    </thead>
                    <tbody>
                    <template  v-if="$root.$data.printHis">
                        <tr v-for="(item,index) in printLis" :key="index" class="print-list">
                            <td>{{item.showlis.names}}</td>
                            <td>{{item.dept}}</td>
                            <td>{{item.fixedtime?item.fixedtime:'非预约单'}}</td>
                            <td>{{item.tour}}</td>
                            <td>{{item.memo}}</td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                    </template>
                    <template v-else>
                        <tr v-for="(item,index) in printLis" class="print-list">
                            <td>{{item.startbed}}</td>
                            <td>{{item.classifyname}}/{{item.catalogname}}</td>
                            <td>
                                {{(item.attribute == 2||item.attribute == 8) ? item.appointment :'非预约单'}}
                            </td>
                            <td>
                                {{item.tackle == '' ? '无' : item.tackle}}
                            </td>
                            <td>{{item.message}}</td>
                            <td>{{item.nurse_name}}</td>
                            <td>
                                <span class="inline-block" v-for="(staff,index) in item.receive">{{staff.receive}}{{(item.receive.length > 0 && index < item.receive.length -1)?'，':''}}</span>
                            </td>
                            <td></td>
                        </tr>
                    </template>

                    </tbody>
                </table>
            </div>
            <div class="footer" v-if="$root.$data.printHis">{{$root.$data.cid == 19?'来源自医嘱单原始信息':'来源自HIS原始信息'}}</div>
        </div>

        <div v-if="isPrint" >
            <div class="modal-bg"></div>
            <div class="patientModal printModal">
                <div class="pHead">是否已经打印？</div>
                <div class="pBottom">
                    <button class="cancel" @click="isPrint=false">没有</button>
                    <button class="sure" @click="surePrint">打印了</button>
                </div>
            </div>
        </div>

    </div>
</template>
<script>
    import today from '../common/today'
    export default{
        props:{
            printLis:{
                type:Array,
                default:function(){
                    return []
                }
            },
            start:''
        },
        data(){
            return{
                isPrint:false,
                pks:'',
                ptime:'',
                ctime:''
            }

        },
        methods:{
            //打印
            printCancel(){
                this.$parent.isprint = false
            },
            printContent(){
                window.print();
                if(!this.$root.$data.printHis){
                    this.isPrint = true;
                }
            },
            surePrint(){
                this.isPrint = false;
                this.$parent.isprint = false
                let id = [],ctime=this.ctime,onlys=new Date(this.ctime.replace(/-/g,'/')).getTime();
                for(var val of this.printLis){
                    id.push(val.id)
                }
                let ektprint = JSON.stringify({"ids":id,"ctime":ctime});
                let localp = {"ids":id,"ctime":ctime,only:onlys}
                this.$emit('isprintfn',ektprint,localp)
            }

        },
        created() {
            document.title = '泰科下单助手';
            jQuery('#app').css({'height':'auto','overflow': 'auto'});
            let ks = this.start.split(' ');
            if(ks.length > 2){
                this.pks = ks[2];
            }else {
                this.pks = ks[0];
            }
            this.ptime = today.init('YY年MM月DD日 hh:mm:ss');
            this.ctime = today.init('YY-MM-DD hh:mm:ss');
            setTimeout(function(){
                this.printContent()
            }.bind(this),100)
        }
    }
</script>
